package server;

/* Record
 * ---------------------------------------------------
 * Written by
 * Rebecca Van Bussel 6271316
 * October 6, 2013
 */


import java.util.Date;

public class Record {

	private String id;

	private String fname;
	private String lname;
	private String address;
	private Date lastDate;
	private String lastLocation;
	private String status;
	private String officerId;
	private final int FNAMELENGTH = 15;
	private final int LNAMELENGTH = 15;
	private final int STATUSLENGTH = 15;
	private final int OFFICERIDLENGTH = 8;
	private final int DATELENGTH = 30;
	private final int ADDRESSLENGTH = 54;

	Record(String fname, String lname, String address, Date lastDate, String lastLocation, String status, String officerId, char type, int num) {
		assert(num<100000);

		this.fname = fname;
		this.lname = lname;
		this.address=address;	
		this.lastDate = lastDate;
		this.lastLocation = lastLocation;
		this.status = status;
		this.officerId=officerId;
		
		if (type=='C') {
			id="CR"+num;
		}
		else if (type=='M')
			id="MR"+num;
		else {
			System.out.println("Error: Unexpected record type");
			System.exit(1);
		}
	}
	
	Record(String fname, String lname, String address, Date lastDate, String lastLocation, String status, String id) {

		this.id=id;
		this.fname = fname;
		this.lname = lname;
		this.address=address;	
		this.lastDate = lastDate;
		this.lastLocation = lastLocation;
		this.status = status;
	}

	public Record(String id) {
		this.id=id;
	}

	public String getFname() {
		return fname;
	}

	public void setFname(String fname) {
		this.fname = fname;
	}

	public String getLname() {
		return lname;
	}

	public void setLname(String lname) {
		this.lname = lname;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Date getLastDate() {
		return lastDate;
	}

	public void setLastDate(Date lastDate) {
		this.lastDate = lastDate;
	}

	public String getLastLocation() {
		return lastLocation;
	}

	public void setLastLocation(String lastLocation) {
		this.lastLocation = lastLocation;
	}

	public String getOfficerId() {
		return officerId;
	}

	public void setOfficerId(String officerId) {
		this.officerId = officerId;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Record other = (Record) obj;
		if (!id.equals(other.id))
			return false;
		return true;
	}

	public String toString() {
		return "ID: "+id+" Last name: "+lname+" Status: "+status+" Officer ID: "+officerId;
	}
	
	public String stringRecord() {
		String newFname=fname+addSpaces(FNAMELENGTH-fname.length());
		String newLname=lname+addSpaces(LNAMELENGTH-lname.length());
		String newAddress=address+addSpaces(ADDRESSLENGTH-address.length());
		String newLocation=lastLocation+addSpaces(ADDRESSLENGTH-lastLocation.length());
		String newStatus=status+addSpaces(STATUSLENGTH-status.length());
		String newOfficerId=officerId+addSpaces(OFFICERIDLENGTH-officerId.length());
		String newDate=lastDate.toString();
		newDate+=addSpaces(DATELENGTH-newDate.length());
		return newFname+newLname+newAddress+newDate+newLocation+newStatus+id+newOfficerId;
	}
	
	private String addSpaces(int numSpaces) {
		String spaces = "";
		for (int i=0;i<numSpaces; i++) {
			spaces+=" ";			
		}
		return spaces;
	}

}
